---扇形碰撞检测
---@class Battle.SectorSelector:Battle.IRangeSelector
local SectorSelector = Battle.CreateClass("SectorSelector",Battle.IRangeSelector)
Battle.SectorSelector = SectorSelector

local tempVec3 = Vector3.New()

function SectorSelector:ctor()
    self.angle = 0
    self.radius = 0
    self.pos = Vector3.New()
    self.forward = Vector3.New()
end
function SectorSelector:Init(pos,forward,radius,param2,angle)
    self.angle = angle
    self.radius = radius
    self.pos:SetV(pos)
    self.forward:SetV(forward)
end
function SectorSelector.GetType()
    return Battle.RangeSelectorType.Sector
end
function SectorSelector:CalculateTargets(targetList)
    local entityList = Battle.ActorManager.GetActorList()
    for k,v in pairs(entityList) do
        if self:CheckDistance(self.pos,v) and self:CheckAngle(self.pos,self.forward,v) then
            table.insert(targetList,v)
        end
    end
end
---@private
---@param v Battle.Entity
function SectorSelector:CheckDistance(pos,v)
    local x = pos.x - v.pos.x
    local z = pos.z - v.pos.z
    local r = self.radius + v.radius
    return x*x+z*z < r*r
end
---@private
---@param v Battle.Entity
function SectorSelector:CheckAngle(pos,forward,v)
    if self.angle == 360 then
        return true
    end
    tempVec3:SetV(v.pos):Sub(pos)
    tempVec3:SetNormalize()
    local angle = Vector3.AngleByNormalize(forward,tempVec3)
    if angle <= self.angle/2 then
        return true
    end
    return false
end
